<?php
namespace Mobile\Controller;
use Mobile\Model\StoreModel;
class UserController extends MobileBaseController {
    public function login(){

        $this->assign('openid',I('openid'));
        $this->display();
    }

    public function do_login()
    {
        if(IS_POST){
            $data = I('post.');
            $username = $data['username'];
            $password = encrypt($data['password']);
            $result = array();
            if(!$username || !$password)
                $result= array('status'=>0,'msg'=>'请填写账号或密码');
            $user = M('users')->where("mobile='{$username}'")->find();
            if(!$user){
                $result = array('status'=>-1,'msg'=>'账号不存在!');
            }elseif($password != $user['password']){
                $result = array('status'=>-2,'msg'=>'密码错误!');
            }elseif($user['is_lock'] == 1){
                $result = array('status'=>-3,'msg'=>'账号异常已被锁定！！！');
            }else{
                //查询用户信息之后, 查询用户的登记昵称
                M('users')->where("user_id = {$user['user_id']}")->save(array('openid'=>$data['openid'],'last_login'=>time()));
                session('user',$user);
                $result = array('code'=>200,'msg'=>'登陆成功','url'=>'/Mobile/pda/index');
            }

            exit(json_encode($result));
        }
    }
} 